var newBidsAjax,newBidAjax;
var newBidsArr = [];
var lastBidPublishTime;

//gets new Bids from the server 
function getNewBids(){
	var url = addTimeToURL("Bids",lastBidPublishTime);
	newBidsAjax = fire("GET",url,new Object(),newBidsListener);
}


//stores the new Bids in the server as well as it calls the UI updater
function newBidsListener(){
	var obj = validResponse(newBidsAjax);
	if (obj != undefined && obj.bids != null){
		for(var i=0;i<obj.bids.length;i++){
			newBidsArr.unshift(obj.bids[i]);
			lastBidPublishTime = obj.bids[i].time;
		}
	fetchNewBids(obj.bids.length,newBidsArr);
	}
}

// store the publish time of the most new item we are showing 


var newBidsCheckingInterval;

function startRefreshingBids(){
// every 5 seconds check for new Bids
	getNewBids();
	newBidsCheckingInterval = setInterval(getNewBids, 5000);
}

startRefreshingBids();

function stopRefreshingBids(){
	clearInterval(newBidsCheckingInterval);
}

//posting a new item
function newBid(params){
	newBidAjax = fire("POST","Bids",params,placeBidListener);
}

function placeBidListener(){
	var obj = validResponse(newBidAjax);
	if (obj != undefined){
		if(obj.result == true){
			modifyCurrentBitAmount();
		}else{
			showError(obj.errorMessage);
		}
	}
}